<template>
	<view class="home">
		<!-- 轮播图 -->
		<swiper indicator-dots circular interval="3000" autoplay>
			<swiper-item v-for="item in swipers" :key="item.id">
				<image :src="item.image_src"></image>
			</swiper-item>
		</swiper>
		<!-- 导航区域 -->
		<view class="nav">
			<view class="nav-item" v-for="(item,index) in navs" :key="index" @click="navItemClick(item.path)">
				<view :class="item.icon"></view>
				<text>{{item.title}}</text>
			</view>
		</view>
		<!-- 商品推荐区域 -->
		<view class="hot_goods">
			<view class="title">推荐商品</view>
			<!-- 使用商品列表组件 并向组件传递goods值-->
			<goods_list :goods="goods"></goods_list>
		</view>
	</view>
</template>

<script>
	// 导入商品列表组件
	import goodsList from '../../components/goods_list/goods_list.vue'
	export default {
		data() {
			return {
				// 轮播图数据
				swipers:[],
				// 热门商品数据
				goods:[],
				// 导航栏数据
				navs:[
					{
						icon:'iconfont icon-ziyuan',
						title:'阿平乐购',
						path:'/pages/goods/goods'
					},
					{
						icon:'iconfont icon-guanyuwomen',
						title:'联系我们',
						path:'/pages/contact/contact'
					},
					{
						icon:'iconfont icon-tupian',
						title:'社区图片',
						path:'/pages/pics/pics'
					},
					{
						icon:'iconfont icon-shipin',
						title:'学习视频',
						path:'/pages/vides/vides'
					},
				]
			}
		},
		onLoad() {
			// 页面创建 调用getSwipers
			this.getSwipers();
			this.getHotGoods();
		},
		methods: {
			// 获取轮播图数据
			getSwipers(){
				this.$myRequest({
					url:'/home/swiperdata'
				}).then((res) => {
					// console.log(res);
					// 保存轮播图数据
					this.swipers = res.data.message
				})
			},
			// 获取热门商品数据
			getHotGoods(){
				this.$myRequest({
					url:'/goods/search?pagenum=7'
				}).then((res) => {
					// console.log(res);
					// 保存热门商品数据
					this.goods = res.data.message.goods
				})
			},
			// 给导航栏添加点击事件
			navItemClick(url){
				// uni.navigateTo 保留当前页面，跳转到某个页面
				// console.log(url);
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style lang="scss">
	.home{
		swiper{
			width: 750rpx;
			height: 380rpx;
			image{
				height: 100%;
				width: 100%;
			}
		}
		.nav{
			display: flex;
			.nav-item{
				flex: 1;
				text-align: center;
				view{
					width: 120rpx;
					height: 120rpx;
					background: $shop-color;
					border-radius: 60rpx;
					margin: 10px auto;
					line-height: 120rpx;
					color: #FFFFFF;
					font-size: 50rpx;
				}
				.icon-tupian{
					font-size: 40rpx;
				}
				text{
					font-size: 30rpx;
				}
			}
		}
		.hot_goods{
			background: #eee;
			overflow: hidden;
			margin-top: 10px;
			.title{
				height: 50px;
				line-height: 50px;
				color: $shop-color;
				text-align: center;
				letter-spacing: 20px; // 字体间距 
				background: #FFFFFF;
				margin: 7rpx 0;
			}
			
		}
	}
</style>
